package com.aaa.mk.service.impl;

import com.aaa.mk.dao.AdvertisePositionDao;
import com.aaa.mk.entity.AdvertisePosition;
import com.aaa.mk.service.AdvertisePositionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 广告位位置(AdvertisePosition)表服务实现类
 *
 * @author han qu
 * @since 2021-02-22 13:55:04
 */
@Service("advertisePositionService")
public class AdvertisePositionServiceImpl implements AdvertisePositionService {
    @Resource
    private AdvertisePositionDao advertisePositionDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public AdvertisePosition queryById(Object id) {
        return this.advertisePositionDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<AdvertisePosition> queryAllByLimit(int offset, int limit) {
        return this.advertisePositionDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param advertisePosition 实例对象
     * @return 实例对象
     */
    @Override
    public AdvertisePosition insert(AdvertisePosition advertisePosition) {
        this.advertisePositionDao.insert(advertisePosition);
        return advertisePosition;
    }

    /**
     * 修改数据
     *
     * @param advertisePosition 实例对象
     * @return 实例对象
     */
    @Override
    public AdvertisePosition update(AdvertisePosition advertisePosition) {
        this.advertisePositionDao.update(advertisePosition);
        return this.queryById(advertisePosition.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Object id) {
        return this.advertisePositionDao.deleteById(id) > 0;
    }

    /**
     * 通过实体作为筛选条件分页查询
     *
     * @param advertisePosition 实例对象
     * @return 对象列表
     */
    @Override
    public PageInfo queryAll(int pageNo, int pageSize, AdvertisePosition advertisePosition) {
        PageHelper.startPage(pageNo, pageSize);
        return new PageInfo<AdvertisePosition>(this.advertisePositionDao.queryAll(advertisePosition));
    }
}